const modules = import.meta.glob(
  [
    '../components/**/*.vue',
    '../components/**/*.tsx',
    '../components/**/*.jsx',
  ],
  {
    eager: true,
  }
) as Record<string, Module>

export default (app: App) => {
  app.use({
    install(app: App) {
      const values = Object.values(modules)
      if (!values.length) return

      values.forEach((module: Module) => {
        if (!module.default.name) {
          console.warn('该组件需要一个name属性 ==> :', module)
          return
        }
        app.component(module.default.name as string, module.default)
      })
    },
  })
}
